﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GameSchool.Models;
using System.Web.Profile;
using System.Web.Security;

namespace GameSchool.Controllers
{
    public class UserController : Controller
    {

		//Sækir prófíl innskráðs notanda
        public ActionResult Index()
        {
            var profile = Profile.GetProfile(this.User.Identity.Name);
            return View(profile);
        }

		// Þegar smellt er á notanda úr lista af notendum þá opnast prófíl síða þess notanda.
		public ActionResult viewUser(string id)
		{
			if (User.Identity.IsAuthenticated)
			{
				var profile = Profile.GetProfile(id);
				ViewData["providerkey"] = Membership.GetUser(id).ProviderUserKey;
				TempData["tempUserID"] = Membership.GetUser(id).ProviderUserKey;
				return View("Profile", profile);
			}
			else
			{
				return RedirectToAction("Index", "Home");
			}
		}

        public ActionResult allUsers()
        {
			var allUsers = Membership
				.GetAllUsers()
				.Cast<MembershipUser>()
				.Select(x => new UserViewModel
				{
					UserName = Profile.GetProfile(x.UserName).UserName.ToString(),
					Name = Profile.GetProfile(x.UserName).FullName.ToString(),
					Ssn = Profile.GetProfile(x.UserName).Ssn.ToString()
				});

			return View(allUsers);
        }




		//Skilar lista af öllum kennurum
		public ActionResult teachers()
		{
			IEnumerable<String> allTeachers = Roles.GetUsersInRole("Teacher");

			List<String> idList= new List<String>();
			foreach (var n in allTeachers)
			{
				Guid UserId = new Guid(Membership.GetUser(n).ProviderUserKey.ToString());
				idList.Add(UserId.ToString());
			}
			//Hér erum við komin með lista sem inniheldur öll userid kennara í grunninum
			//Hvernig næ ég svo nöfnunum þeirra ??????????
			//To be continued
			ViewData["listOfTeachers"] = new SelectList(idList, "ID", "Name");

			return View();
		}
    }
}
